package com.anysoft.utils;

import android.os.Environment;

import com.blankj.utilcode.util.FileUtils;
import com.anysoft.me.config.CommentConfig;

import java.io.File;


/**
 * Created by lty on 2017/12/19.
 */

public class DiskUtils {

    /**
     * sdcard目录
     */
    public static String SDPATH = Environment.getExternalStorageDirectory().getPath();

    /**
     * 项目根目录
     */
    public static final String ROOT_PATH = SDPATH + "/" + CommentConfig.DOWNLOAD_DIR_NAME;
    /**
     * 下载目录
     */
    public static final String DOWNLOAD_PATH = ROOT_PATH + "/download";

    /**
     * 缓存目录
     */
    public static final String CACHE_PATH = ROOT_PATH + "/cacheDir";

    /**
     * 缓存图片的目录
     */
    public static final String CACHE_IMAGE_PATH = CACHE_PATH + "/images";

    /**
     * 缓存log的目录
     */
    public static final String CACHE_LOG_PATH = CACHE_PATH + "/log";


    static {
        createFileHolder(DOWNLOAD_PATH);
        createFileHolder(CACHE_PATH);
        createFileHolder(CACHE_IMAGE_PATH);
        createFileHolder(CACHE_LOG_PATH);
    }

    /**
     * 判断某个文件目录是否存在,不存在创建
     *
     * @param filePath
     * @return
     */
    public static boolean isExistsDir(String filePath) {
        if (FileUtils.createOrExistsDir(filePath)) {
            return true;
        }
        return false;
    }

    /**
     * 判断某个文件是否存在
     *
     * @param filePath
     * @return
     */
    public static boolean isExistsFile(String filePath) {
        if (FileUtils.createOrExistsFile(filePath)) {
            return true;
        }
        return false;
    }

    public static void createFileHolder(String fileHolder) {
        File file = new File(fileHolder);
        if (!file.exists()) {
            file.mkdirs();
        }
        MentorLogger.Loge("文件路劲: " + file.getPath());
    }
}
